home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CRIBBAGE.PAK / CARDS.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  3KB  |  96 lines

  1. //--------------------------------------------------------------------------
  2. // Turbo Cribbage -- Copyright (c) 1995, Borland International
  3. //--------------------------------------------------------------------------
  4. #ifndef CARDS_H
  5. #define CARDS_H
  6.  
  7. #include <owl/window.h>
  8. #include <assert.h>
  9.  
  10. //
  11. // TCard -- a class which defines a single playing card.  The card
  12. // has the following properties:
  13. //
  14. //   rank      -- 1-13, 1=ace, 13=king
  15. //   suit      -- 0-3, hearts, diamons, spades, clubs
  16. //   backStyle -- 0-13, one of 13 back styles
  17. //   faceUp    -- bool, is the card face up or down
  18. //
  19. class TCard {
  20.   public:
  21.     int  rank, suit, backStyle;
  22.     BOOL faceUp;
  23.     TCard(int aRank = 0, int aSuit = 0, int aBackStyle = 0, BOOL aFaceUp = FALSE) {
  24.       rank = aRank;
  25.       suit = aSuit;
  26.       backStyle = aBackStyle;
  27.       faceUp = aFaceUp;
  28.     }
  29.     TCard(TCard& card) {
  30.       *this = card;
  31.     }
  32.     static const char *Stringify(int r, int s) {
  33.       strcpy(buffer, rankStr[r]);
  34.       strcat(buffer, suitStr[s]);
  35.       return buffer;
  36.     }
  37.     const char *Stringify() {
  38.       return Stringify(rank, suit);
  39.     }
  40.   private:
  41.     static char *rankStr[14];
  42.     static char *suitStr[4];
  43.     static char buffer[10];
  44. };
  45.  
  46. //
  47. // TCardGroup -- defines a group of cards.  At construction time, you
  48. // must specifiy the maximum # of cards allowed in the group.  Then
  49. // you can insert and remove cards.  TDeck is derived from this class.
  50. //
  51. #ifdef _OWLDLL
  52. class _huge TCardGroup {
  53. #else
  54. class TCardGroup {
  55. #endif
  56.   public:
  57.     TCardGroup(int aMaxCards);
  58.     ~TCardGroup();
  59.     int GetCount() { return count; }          // get current # of cards in group
  60.     int GetMaxCards() { return maxCards; }
  61.     int Insert(TCard* card);               // insert card (returns index)
  62.     void Insert(TCardGroup* cardGroup);     // insert group of cards
  63.     virtual TCard* Remove(int position=0);          // remove card
  64.     const TCard& operator[](int position);  // access card without removing it
  65.  
  66.   protected:
  67.     TCard **cards;
  68.  
  69.   private:
  70.     int   maxCards,   // max # of cards that this group can contain
  71.           count;      // current # of cards that this group contains
  72.  
  73.     TCardGroup& operator =(TCardGroup&) { return *this; }
  74.     TCardGroup(TCardGroup&) {}
  75. };
  76.  
  77. //
  78. // TDeck -- derived from TCardGroup, automatically creates a group of
  79. // 52 cards.  Added functions for shuffling, cutting, and dealing the
  80. // cards
  81. //
  82. class TDeck : public TCardGroup {
  83.   public:
  84.     TDeck(int backStyle = 0);
  85.  
  86.     TCard* DealCard();                 // removes the top card from the deck
  87.     void Shuffle(int shuffleCount);  // shuffle cards
  88.     void Cut(int cutPosition);       // cut cards at given position
  89.     void ResetBackStyle(int newBackStyle);
  90.     const char * EncodeDeck();
  91.     BOOL DecodeDeck(const char* encodedDeck);
  92.     void Initialize(int backStyle);
  93. };
  94.  
  95. #endif // CARDS_H
  96.